﻿using M_ApiResult;
using M_Quality.API.Application.Command.QualitygroupCommand;
using M_Quality.Domain.Dto;
using M_Quality.Domain;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using M_Quality.API.Application.Command.QualityinspectionCommand;

namespace M_Quality.API.Controllers
{
    /// <summary>
    /// 质检项目
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class QualityspectionController : ControllerBase
    {
        protected readonly IMediator mediator;

        public QualityspectionController(IMediator mediator)
        {
            this.mediator = mediator;
        }


        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddQualityspection(QualityinspectionCreateCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {

                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;

        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DelQualitspection(QualityinspectionDeleteCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();

            try
            {
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<Qualityinspection>> BackfillQualityspection([FromQuery] QualityinspectionbackfillCommand command)
        {
            ApiResult<Qualityinspection> result = new ApiResult<Qualityinspection>();
            try
            {
                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;

        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateQualityspection(QualityinspectionUpdateCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {

                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;

        }
        /// <summary>
        /// 显示
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<PageDto<Qualityinspection>>> Showspection([FromQuery] QualityinspectionshowCommand command)
        {
            ApiResult<PageDto<Qualityinspection>> result = new ApiResult<PageDto<Qualityinspection>>();
            try
            {

                result.Data = await mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;

        }

    }
}
